package com.yukefms.engine.senario;

import com.yukefms.rule.TriggerResponseBARule;
import com.yukefms.rule.formula.*;
import com.yukefms.rule.formula.basis.HorizonalBelowFormula;
import com.yukefms.rule.formula.basis.InParallelFormula;
import com.yukefms.rule.formula.basis.SitDownDynamicBAFormula;
import com.yukefms.rule.formula.interfaces.DynamicBAFormula;
import com.yukefms.rule.formula.interfaces.StaticBAFormula;
import com.yukefms.rule.interfaces.BAStageRule;

/**
 * @Description
 * @Author Ping
 * @Date 2021/7/17 17:07
 **/
public class DeepSquartSenario implements Senario {
    public static final String RULE_NAME = "DEEP-SQUART" ;
    // MOVING_LENGTH_EPSILON = 0.002
    // more larger, more easy to reach
    public static final double MOVING_UNDER_BELOW = 0.01;

    @Override
    public BAStageRule buildRule(String ruleName) {
        TriggerResponseBARule.TriggerResponseRuleBuilder ruleBuilder = TriggerResponseBARule.builder() ;

        /**
         * Trigger Part
         *
         */
        StaticBAFormulaChain trigger = new StaticBAFormulaChain() ;
        trigger.setScore(1);
        /**
         * (1) two shoulders and two elbows should be in parallel
         * (2) two shoulder and two Knees should be in parallel
         * (3) two legs in parallel
         */
        trigger.add(new InParallelFormula("6", "10","4", "8"))
                .add(new InParallelFormula("4","8", "17","13"))
                .add(new InParallelFormula("17","18", "13","14"))
                .add(new HorizonalBelowFormula("3","9"));
        trigger.setName("HANDS-UP-STAND-WELL");
        trigger.setDescription("[TO MAKE] Shoulder Elbow in parallel\n Two Shoulders Keens Parallel\n Legs in Parallel");
        /**
         * Performing Part
         * (1) sit down
         */
        DynamicBAFormula dynamic = new SitDownDynamicBAFormula() ;
        dynamic.setName("SITING-DOWN");
        //dynamic.setScore(2);
        /* Response part
         (1) below horizonal level
       */
        // [PARAMETER]
        StaticBAFormula response = new HorizonalBelowFormula("0", "17", MOVING_UNDER_BELOW) ;
        response.setName("SIT-BELOW-HORIZONAL");

        SimpleStageBAFormula stage = new SimpleStageBAFormula(dynamic, response) ;
        stage.setName("SITING-DOWN") ;
        stage.setScore(2);

        BAStageRule rule = ruleBuilder.setTrigger(trigger)
                                .setStage(stage)
                                 .setInvariant(trigger)
                                .setRuleName(ruleName)
                                .build() ;
        rule.setSuccessScore(3);

        return rule ;




    }

}
